package com.wxl.demo.login;

import com.wxl.demo.model.UserInfo;
import com.wxl.demo.service.UserInfoService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/login")
public class LoginController {
	@Resource
	private UserInfoService userService;

	@RequestMapping("/toLogin")
	public String login(Model model){
		System.out.println("================++++++++++++++跳转登录页面");
		return "login";
	}

	@RequestMapping("loginSystem")
	public String loginSystem(String username, String password, HttpSession session){
		UserInfo userInfo = userService.getUserByName(username);
		if (userInfo != null && password.equals(userInfo.getPassword())){
			System.out.println("合法用户");
			session.setAttribute("username",username+System.currentTimeMillis());
			return "redirect:/demo/result";
		}else {
			System.out.println("非法用户,返回登陆页");
			return "redirect:/login/toLogin";
		}
	}
}
